#ifndef __STREAM_H__
#define __STREAM_H__

typedef enum
{
  SeekSet,
  SeekCur,
  SeekEnd
} SeekWhence;

#define STREAM_CAST(x) ((Stream *)(x))

typedef struct _Stream
{
  void (*write)(struct _Stream *, void *, int);
  int (*read)(struct _Stream *, void *, int, int);
  /* A seek past the end of the stream should extend the stream size */
  void (*seek)(struct _Stream *, int, SeekWhence);
  int (*pos)(struct _Stream *);
  int (*size)(struct _Stream *);
  void (*close)(struct _Stream *);
} Stream;

void stream_create (Stream *s);

static void stream_write (Stream *s, void *, int);
static int stream_read (Stream *s, void *, int, int);
static void stream_seek (Stream *s, int, SeekWhence);
static int stream_pos (Stream *s);
static int stream_size (Stream *s);
static void stream_close (Stream *s);

#endif
